package com.wanho.java157.ProductManagement.controller;


import com.wanho.java157.ProductManagement.po.Orders;
import com.wanho.java157.ProductManagement.po.Product;
import com.wanho.java157.ProductManagement.po.ProductInventory;
import com.wanho.java157.ProductManagement.po.Store;
import com.wanho.java157.ProductManagement.service.InventoryService;
import com.wanho.java157.ProductManagement.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.List;

@Controller
@RequestMapping("/orders")
@SessionAttributes({"orders"})
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/list")
    public String li(Model model,String status) {
        List<Orders> orders = ordersService.selectByStatus(status);

        model.addAttribute("orders",orders);

        return "view/productManage/stock/index";
    }

    @RequestMapping("/update")
    public String modify(Model model,String status,int id) {

        boolean b = ordersService.modifyStatusById(status, id);
        System.out.println(b);


        List<Orders> orders = ordersService.selectByStatus("");
        model.addAttribute("orders",orders);
        return "view/productManage/stock/index";
    }

    @RequestMapping("/updateView")
    public String view(Model model, int id) {

        Orders orders = ordersService.selectById(id);
        model.addAttribute("orders",orders);
        return "view/productManage/stock/update";
    }

    @RequestMapping("/saleList")
    public String saleLi(Model model,String status) {
        List<Orders> orders = ordersService.selectByStatus(status);

        model.addAttribute("orders",orders);

        return "view/productManage/sales/index";
    }

    @RequestMapping("/saleOrder")
    public String saleOr(Model model,String field) {
        List<Orders> orders = ordersService.selectOrder(field);

        model.addAttribute("orders",orders);

        return "view/productManage/sales/index";
    }


}

